package com.jxc.jxc01.grc.web;

import com.jxc.jxc01.grc.entity.Vendor;
import com.jxc.jxc01.grc.service.IVendorService;
import com.jxc.jxc01.grc.service.impl.VendorServiceImpl;
import com.jxc.jxc01.grc.entity.Vendor;
import com.jxc.jxc01.grc.service.IVendorService;
import com.jxc.jxc01.grc.service.impl.VendorServiceImpl;
import jdk.internal.org.objectweb.asm.tree.analysis.Value;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.time.temporal.ValueRange;

@WebServlet(value = "/addVendor")
public class AddVendorServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request,
                           HttpServletResponse response)
            throws ServletException, IOException {
        IVendorService vendorService = new VendorServiceImpl();
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        System.out.println("addVendor");
        String name = request.getParameter("suppliername");
        String head = request.getParameter("headname");
        String phone = request.getParameter("phone");
        String address = request.getParameter("address");
        String bank = request.getParameter("bank");
        String creationtime = request.getParameter("creationtime");
        String updatetime = request.getParameter("updatetime");

        Vendor vendor = new Vendor();
        vendor.setSuppliername(name);
        vendor.setHeadname(head);
        vendor.setPhone(phone);
        vendor.setAddress(address);
        vendor.setBank(bank);
        vendor.setCreationtime(creationtime);
        vendor.setUpdatetime(updatetime);

        int i = vendorService.addVendor(vendor);
        if (i > 0){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }
}
